package ar.edu.utn.creatorClass;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

import ar.edu.utn.bean.InstanceObject;
import ar.edu.utn.bean.TypeOfProperty;
import ar.edu.utn.fixture.PersonaService;

//TODO si no se usa tirar la clase entera
public class InstanceCreator {
	public InstanceObject instanceObject (String className, Constructor constructor, List<TypeOfProperty> fieldsValues) throws Exception{
		
		Class testClass = Class.forName(className);
		
		Constructor[] constructores = testClass.getConstructors();
		
		Field[] campos = testClass.getFields();
		
		Method[] metodos = testClass.getMethods();
		
		Object object = testClass.getConstructor(String.class,Integer.class).newInstance("roberto",2);
		
		String metodo = "pepePepe2";
		
		Class classes[] = {}; 
		
		Object parameters[] = {};
		
//		System.out.println(object.getClass().getMethod(metodo, classes).invoke(object,parameters));
		
		Class stringClass = Class.forName("java.lang.String");
		
		String roberto = "roberto";
		
		InstanceObject<String> robertoTest = new InstanceObject<String>();
		
		robertoTest.setClasses(java.lang.String.class);
		
		robertoTest.setObject(roberto);
		
		Object objeto = testClass.getConstructor(robertoTest.getClasses()).newInstance(robertoTest.getObject());
		
		InstanceObject instance = new InstanceObject();
		
		Field field = objeto.getClass().getField("pepe");
		
		String roberto2 = "telma";
		
		field.set(objeto, roberto2);
		
		Class prueba = robertoTest.getClass();
		
		Field t = robertoTest.getClass().getField("t");
		
		System.out.println(objeto.getClass().getMethod(metodo, classes).invoke(objeto,parameters));
		
		PersonaService rabito = new PersonaService(2, "roberto");
		
		Class rabitoClass = rabito.getClass();
		
		instance.setClasses(testClass);
		
		instance.setObject(object);
		
		return instance;
	}
	
	public InstanceObject instanceObject (String className, List<TypeOfProperty> fieldsValues) throws Exception{
		Class testClass = Class.forName(className);
		
		Constructor[] constructores = testClass.getConstructors();
		
		Field[] campos = testClass.getFields();
		
		Method[] metodos = testClass.getMethods();
		
		Object object = testClass.getConstructor(String.class,Integer.class).newInstance("roberto",2);
		
		String metodo = "pepePepe2";
		
		Class classes[] = {}; 
		
		Object parameters[] = {};
		
//		System.out.println(object.getClass().getMethod(metodo, classes).invoke(object,parameters));
		
		Class stringClass = Class.forName("java.lang.String");
		
		String roberto = "roberto";
		
		InstanceObject<String> robertoTest = new InstanceObject<String>();
		
		robertoTest.setClasses(java.lang.String.class);
		
		robertoTest.setObject(roberto);
		
		Object objeto = testClass.getConstructor(robertoTest.getClasses()).newInstance(robertoTest.getObject());
		
		InstanceObject instance = new InstanceObject();
		
		Field field = objeto.getClass().getField("pepe");
		
		String roberto2 = "telma";
		
		field.set(objeto, roberto2);
		
		Class prueba = robertoTest.getClass();
		
		Field t = robertoTest.getClass().getField("t");
		
		System.out.println(objeto.getClass().getMethod(metodo, classes).invoke(objeto,parameters));
		
		PersonaService rabito = new PersonaService(2,"roberto");
		
		Class rabitoClass = rabito.getClass();
		
		instance.setClasses(testClass);
		
		instance.setObject(object);
		
		return instance;
	}
}
